
	/* unicloud的数据库操作函数封装
	 ** @method（必须） 增删改查方法add，remove, query, count, update
	 ** @collection（必须） 数据库集合名称
	 ** @query（可选） 其他参数，包括doc,where等
	 */
	const db = (method, collection, query = {}) => {
		uni.showLoading({
			title: '执行中'
		})

		// 解构query
		const {
			data,
			doc,
			queryItem
		} = query

		// 返回一个Promise
		return new Promise((resolve, reject) => {
			uniCloud.callFunction({
				name: 'db',
				data: {
					method,
					collection,
					data: data || '',
					doc: doc || '',
					// where: queryItem.where || '',
					// order: queryItem.order || '',
					// skip: queryItem.skip || '',
					// limit: queryItem.limit || '',
					// field: queryItem.field || ''
					queryItem: queryItem || {}
				},
				success: (res) => {
					resolve(res);
				},
				fail: (err) => {
					console.log('err', err);
					reject(err);
				},
				complete: (res) => {
					uni.hideLoading()
				}
			})
		})
	}

	// unicloud上传
	const upload = (filePath) => {
		uni.showLoading({
			title: '上传中'
		})
		return new Promise((resolve, reject) => {
			uniCloud.uploadFile({
				filePath: filePath,
				success: (res) => {
					resolve(res);
				},
				fail: (err) => {
					console.log('err', err);
					reject(err);
				},
				complete: (res) => {
					uni.hideLoading()
				}
			})
		})
	}

	// unicloud删除存储
	const remove = (fileID) => {
		uni.showLoading({
			title: '删除中'
		})
		uniCloud.deleteFile({
			fileList: [fileID],
			success: (res) => {
				resolve(res);
			},
			fail: (err) => {
				console.log('err', err);
				reject(err);
			},
			complete: (res) => {
				uni.hideLoading()
			}
		})
	}


export {
	db,
	upload,
	remove
}